//
//  KLCustomNavBar.m
//  BIBILILI
//
//  Created by WTFKL on 2017/9/19.
//  Copyright © 2017年 WTF. All rights reserved.
//

#import "KLCustomNavBar.h"
@interface KLCustomNavBar()

@end

@implementation KLCustomNavBar

-(UIButton *)leftButton{
    if (!_leftButton) {
        _leftButton = [[UIButton alloc] initButtonWithFrame:CGRectMake(0,0,0,0) title:nil imageName:@"live_danmakuVertical"];
    }
    return _leftButton;
}

-(UIButton *)recomendButton{
    if (!_recomendButton) {
        _recomendButton = [[UIButton alloc] initButtonWithFrame:CGRectMake(0,0,0,0) title:@"推荐" imageName:nil];
        _recomendButton.tag = 1;
        [_recomendButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _recomendButton;
}

-(UIButton *)liveButton{
    if (!_liveButton) {
        _liveButton = [[UIButton alloc] initButtonWithFrame:CGRectMake(0,0,0,0) title:@"直播" imageName:nil];
        _liveButton.tag = 0;
        [_liveButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _liveButton;
}

-(UIButton *)followButton{
    if (!_followButton) {
        _followButton = [[UIButton alloc] initButtonWithFrame:CGRectMake(0,0,0,0) title:@"追番" imageName:nil];
        _followButton.tag = 2;
        [_followButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _followButton;
}

-(UIView *)line{
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        _line.backgroundColor = [UIColor whiteColor];
    }
    return _line;
}

-(UIButton *)rightButton{
    if (!_rightButton) {
        _rightButton = [[UIButton alloc] initButtonWithFrame:CGRectMake(0,0,0,0) title:nil imageName:@"home_search_white"];
    }
    return _rightButton;
}




-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.line];
        [self addSubview:self.leftButton];
        [self addSubview:self.recomendButton];
        [self addSubview:self.liveButton];
        [self addSubview:self.followButton];
//        [self addSubview:self.rightButton];
    }
    return self;
}




-(void)click:(UIButton *)button{
    button.selected = YES;
    [UIView animateWithDuration:0.5 animations:^{
        self.line.kl_centerX = button.kl_centerX;
    }];
    
    if ([self.delegate respondsToSelector:@selector(pushtoViewWithTag:)]) {
        [self.delegate pushtoViewWithTag:button.tag];
    }
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat marginY = 20;
    if(__KLSTATUSBARHEIGHT__ > 20){
        marginY = 40;
    }
    __kWeakSelf__;
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf).with.offset(__KNewSize(marginY));
        make.left.mas_equalTo(weakSelf).with.offset(__KNewSize(20));
        make.size.mas_equalTo(CGSizeMake(__kNewWidth(60), __kNewHeight(48)));
    }];
    //暂不开放右边按钮
//    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(weakSelf).with.offset(__KNewSize(20));
//        make.right.mas_equalTo(weakSelf).with.offset(-20);
//        make.size.mas_equalTo(CGSizeMake(__KNewSize(44), __KNewSize(44)));
//    }];
    [self.recomendButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf).with.offset(__KNewSize(marginY));
        make.centerX.mas_equalTo(weakSelf);
        make.size.mas_equalTo(CGSizeMake(__kNewWidth(80), __kNewHeight(80)));
    }];
    [self.liveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf).with.offset(__KNewSize(marginY));
        make.right.mas_equalTo(weakSelf.recomendButton).with.offset(-50);
        make.size.mas_equalTo(CGSizeMake(__kNewWidth(80), __kNewHeight(80)));
    }];
    [self.followButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf).with.offset(__KNewSize(marginY));
        make.left.mas_equalTo(weakSelf.recomendButton).with.offset(50);
        make.size.mas_equalTo(CGSizeMake(__kNewWidth(80), __kNewHeight(80)));
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.recomendButton.mas_bottom).with.offset(__KNewSize(-10));
            make.centerX.mas_equalTo(weakSelf.recomendButton);
            make.size.mas_equalTo(CGSizeMake(__kNewWidth(60), __kNewHeight(2)));
    }];
    
    
}

@end
